package su.samlib.informer.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class Author implements Parcelable {
	private Library library = new Library();
	private boolean isIgnored;
	private String comment;
	private String category;
	private String name;
	private String author_uri;
	private Date update_date = new Date();
	private boolean isNew;
	private List<Book> texts = new ArrayList<Book>();

	public void setLibraryId(Library lib) {
		this.library = lib;
	}

	public Library getLibraryId() {
		return library;
	}

	public boolean isIgnored() {
		return isIgnored;
	}

	public void setIsIgnored(boolean isIgnored) {
		this.isIgnored = isIgnored;
	}

	public void setComment(final String comment) {
		this.comment = comment;
	}

	public String getComment() {
		if (comment == null)
			return new String();

		return comment;
	}

	public void setCategory(final String category) {
		this.category = category;
	}

	public String getCategory() {
		if (category == null)
			return new String();
		return category;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public String getName() {
		if (name == null)
			return new String();
		return name;
	}

	public void setAuthorUri(final String uri) {
		this.author_uri = uri;

	}

	public String getAuthorUri() {
		if (author_uri == null)
			return new String();
		return author_uri;
	}

	public void setUpdateDate(final Date updateDate) {
		this.update_date = updateDate;
	}

	public Date getUpdateDate() {
		if (update_date == null)
			return new Date();
		return update_date;
	}

	public boolean isNew() {
		return isNew;
	}

	public void setIsNew(boolean isNew) {
		this.isNew = isNew;
	}

	public List<Book> getTexts() {
		return texts;
	}

	public void setTexts(List<Book> texts) {
		this.texts = texts;
	}

	public Author() {
		// TODO Auto-generated constructor stub
	}

	public Author(String name, String uri, Date updateDate, boolean isNew) {
		setName(name);
		setAuthorUri(uri);
		setUpdateDate(updateDate);
		setIsNew(isNew);
	}

	public Author(Parcel in) {
//		id = in.readInt();
		// isIgnored = in.readInt();
//		comment = in.readString();
//		category = in.readString();
		name = in.readString();
		author_uri = in.readString();
//		update_date = new Date(Date.parse(in.readString()));
		// isNew = in.readInt();
		in.readArray(ClassLoader.getSystemClassLoader());
	}

	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
//		dest.writeInt(id);
		// dest.writeInt(isIgnored);
//		dest.writeString(comment);
//		dest.writeString(category);
		dest.writeString(name);
		dest.writeString(author_uri);
//		dest.writeString(update_date.toLocaleString());
		// dest.writeInt(isNew);
		Book[] tmpTexts = texts.toArray(new Book[texts.size()]);
		dest.writeParcelableArray( tmpTexts, PARCELABLE_WRITE_RETURN_VALUE);
	}

	public static final Parcelable.Creator<Author> CREATOR = new Parcelable.Creator<Author>() {

		public Author createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			return new Author(source);
		}

		public Author[] newArray(int size) {
			// TODO Auto-generated method stub
			return new Author[size];
		}

	};
}
